
//
//  UserAccountTool.m
//  kuangjia
//
//  Created by 张帅 on 15/9/29.
//  Copyright © 2015年 ZhangShuai. All rights reserved.
//

#define accountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.plist"]

#import "UserAccountTool.h"


@implementation UserAccountTool


+(BOOL)userLogon{
    
    return [UserAccountTool loadUserAccount]!=nil;
}

+ (void)saveAccount:(UserAccount *)account{
    
    NSLog(@"保存路径%@",accountPath);
    
    [NSKeyedArchiver archiveRootObject:account toFile: accountPath];

}


+(UserAccount *)loadUserAccount{


               // 加载模型
        
    UserAccount *account =[NSKeyedUnarchiver unarchiveObjectWithFile:accountPath];
    
    long long expires_in = [account.expires_in longLongValue];
    
    NSDate * expiresDate= [account.expiresDate dateByAddingTimeInterval:expires_in];
    
    NSDate * now =[NSDate date];
    
    NSComparisonResult  result  =[ expiresDate compare: now];
    
    if (result != NSOrderedDescending) {
        return nil;
    }
    
    return  account;
    
}


@end
